<template>
	<view>
		<bg-video></bg-video>
		<cu-custom bgColor="bg-pink" :isBack="true">
			<block class="text-white" slot="content">课程列表</block>
		</cu-custom>
		<view>
			<view class="padding-xs">
				<view class="bg-white shadow radius margin-bottom-xs" v-for="(kc,index) in kcs" :key="index">
					<kc-item :path="'/pages/cjl'" :isEdit="kc.jlid == currentJl.jlid" :kc="kc"></kc-item>
				</view>
			</view>
			<view v-if="kcs.length < pageInfo.total" class="padding ">
				<button @tap="loadMore" class="cu-btn block bg-pink lg">显示更多</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data: function() {
			return {
				jlid: "",
				mdid: "",
				roomid: "",
				key: "",
				kcs: [],
				pageInfo: {
					current: 1,
					size: 16,
					total: 0,
				}
			};
		},
		computed: {
			currentJl: function() {
				return this.store.state.jl;
			}
		},
		onShareAppMessage: function(){
			return {
				title: this.store.state.title,
				path: '/pages/first?id='+this.store.state.client.clientid
			}
		},
		onLoad: function(option) {
			if (option.jlid) {
				this.jlid = option.jlid;
			}
			if (option.mdid) {
				this.mdid = option.mdid;
			}
			if (option.roomid) {
				this.roomid = option.roomid;
			}
			this.search();
		},
		methods: {
			toNewKc: function() {
				if (this.store.state.jl.yj == 0) {
					this.message.info("请先缴纳保证金");
					return;
				}
				if (this.store.state.jl.tx) {
					
				} else {
					this.message.info("请先录入人脸，否则无法进入门店");
					return;
				}
				uni.navigateTo({
					url: '/pages/cjl/kc/new'
				});
			},
			search: function() {
				this.kcs = [];
				this.pageInfo.current = 1;
				this.loadKc();
			},
			loadMore: function() {
				this.pageInfo.current++;
				this.loadKc();
			},
			loadKc: function() {
				this.api("/kc/page").send({
					current: this.pageInfo.current,
					size: this.pageInfo.size,
					jlid: this.jlid,
					astoreid: this.mdid,
					aroomid: this.roomid,
					searchKey: this.key
				}).then(data => {
					for (let index in data.akechengs.records) {
						let record = data.akechengs.records[index];
						this.kcs.push(record);
					}
					this.pageInfo.total = data.akechengs.total;
				});
			}
		}
	}
</script>

<style>

</style>